//
//  SectionHeaderCellData.m
//  18Birdies
//
//  Created by Lc on 15/5/12.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import "LcFoundation.h"
#import "SectionHeaderCell.h"
#import "SectionHeaderCellData.h"

@implementation SectionHeaderCellData

+ (SectionHeaderCellData*)cellDataWithTitle:(NSString*)title {
  SectionHeaderCellData* cellData = [[self alloc] init];
  cellData->_title = title.copy;
  cellData.clickable = NO;
  return cellData;
}

+ (SectionHeaderCellData*)cellDataWithAttributeTitle:
    (NSAttributedString*)attributeTitle {
  SectionHeaderCellData* cellData = [[self alloc] init];
  cellData->_attributeTitle = attributeTitle.copy;
  cellData.clickable = NO;
  return cellData;
}

- (Class)cellClazz {
  return SectionHeaderCell.class;
}

- (NSString*)nibName {
  return @"SectionHeaderCell";
}

- (void)refreshCell:(SectionHeaderCell*)cell {
  [super refreshCell:cell];
  if (self.backgroundColor != nil) {
    cell.backgroundColor = self.backgroundColor;
  }
  if (self.title != nil) {
    cell.titleLabel.attributedText = nil;
    cell.titleLabel.text = self.title;
    cell.titleLabel.font = self.font;
    if (self.textColor != nil) {
      cell.titleLabel.textColor = self.textColor;
    }
    if (self.topPadding != 0) {
      cell.titleTopConstraint.constant = self.topPadding;
    }
    if (self.bottomPadding != 0) {
      cell.titleBottomConstraint.constant = self.bottomPadding;
    }
  } else if (self.attributeTitle != nil) {
    cell.titleLabel.text = nil;
    cell.titleLabel.attributedText = self.attributeTitle;
  } else {
    LC_FAIL();
  }
  [cell.arrowImageView setHidden:!self.isShowArrow];
  if (self.detailInfo.length > 0) {
    [cell.detailLabel setHidden:NO];
    cell.detailLabel.text = self.detailInfo;
  } else {
    [cell.detailLabel setHidden:YES];
    cell.detailLabel.text = @"";
    [cell.arrowImageView setHidden:YES];
  }
}

@end
